package com.sun.hunk.hibernate.domain.impl;

import com.sun.hunk.hibernate.domain.GenericCode;
import com.sun.hunk.hibernate.domain.ItemCharge;
import com.sun.hunk.hibernate.domain.Purchase;
import com.sun.hunk.hibernate.domain.Sales;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 *
 * @author sunil
 */
@Entity
@Table(name = "item_charge")
public class ItemChargeImpl implements ItemCharge {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @JoinColumn(name = "charge_id")
    @ManyToOne(targetEntity=GenericCodeImpl.class)
    private GenericCode charge;
    @Column(name = "amount")
    private Double amount;
    @JoinColumn(name = "sales_id", referencedColumnName = "id")
    @ManyToOne(targetEntity=SalesImpl.class)
    private Sales sales;
    @JoinColumn(name = "purchase_id", referencedColumnName = "id")
    @ManyToOne(targetEntity=PurchaseImpl.class)
    private Purchase purchase;

    public ItemChargeImpl() {
        charge = DomainFactory.getGenericCode();
    }

    public ItemChargeImpl(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public GenericCode getCharge() {
        return charge;
    }

    public void setCharge(GenericCode charge) {
        this.charge = charge;
    }

    public Double getAmount() {
        return amount;
    }

    public void setAmount(Double amount) {
        this.amount = amount;
    }

    public Sales getSales() {
        return sales;
    }

    public void setSales(Sales sales) {
        this.sales = sales;
    }

    public Purchase getPurchase() {
        return purchase;
    }

    public void setPurchase(Purchase purchase) {
        this.purchase = purchase;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ItemChargeImpl)) {
            return false;
        }
        ItemChargeImpl other = (ItemChargeImpl) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.sun.hunk.hibernate.domain.ItemCharge[id=" + id + "]";
    }

}
